﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V4.Widget;
using Android.Views;
using Android.Widget;
using Medicine.Core.Listeners;

namespace Medicine.Activities
{
    [Activity(Label = "查询药品信息")]
    public class QueryInfoActivity : QueryInfoBaseActivity
    {

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.QueryInfoLayout);
            SetInitControl(this,Resource.Id.queryListView,Resource.Id.swQuery);
            #region 查询
            Button btn = FindViewById<Button>(Resource.Id.Btn_QueryInfo);
            btn.Click += SetQuery;

            #endregion
        }

        private void SetQuery(object sender, EventArgs e)
        {
            var txt = FindViewById<TextInputEditText>(Resource.Id.Txt_QueryExpression);
            if (string.IsNullOrEmpty(txt.Text))
            {
                Helpers.MessageShow.ShowShortMsg(this, "请输入要查询的关键字");
                return;
            }
            var keyStr = txt.Text;
            Expression<Func<Models.Medicine, bool>> expression = s => s.MedicineName.Contains(keyStr)
                                                                        || s.Origin.Contains(keyStr)
                                                                        || s.Purposes.Contains(keyStr);
            (_listView.Adapter as Medicine.Models.MedicineAdapter).SetQueryExpression(expression);
            (_listView.Adapter as Medicine.Models.MedicineAdapter).NotifyDataSetChanged();
        }
    }
}